package com.hdu.seckilldemo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置类
  */

//@Configuration
public class RabbitMQConfigFanout {
    private static final String QUEUE01 = "queue_fanout01";
    private static final String QUEUE02 = "queue_fanout02";
    private static final String EXCHANGE = "fanoutExchange";

    @Bean
    public Queue queue() {
        //创建一个队列 配置消息持久化
        return new Queue("queue", true);
    }

    @Bean
    public Queue queue01() {
        //配置fanout queue01
        return new Queue(QUEUE01);
    }

    @Bean
    public Queue queue02() {
        //配置fanout queue02
        return new Queue(QUEUE02);
    }
    @Bean
    public FanoutExchange fanoutExchange(){
        //配置交换机
        return new FanoutExchange(EXCHANGE);
    }

    @Bean
    public Binding binding01(){
        //将队列queue01 绑定到交换机exchange上
        return BindingBuilder.bind(queue01()).to(fanoutExchange());
    }
    @Bean
    public Binding binding02(){
        //将队列queue02 绑定到交换机exchange上
        return BindingBuilder.bind(queue02()).to(fanoutExchange());
    }

}